﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using CSP.Model.Presenter;
using CSP.Model.Entities;
using System.Collections.Generic;

namespace CSP.WebControls
{
    public partial class FollowerRequests : System.Web.UI.UserControl, IFollowerRequestsPresenter
    {
        private FollowerRequestsPresenter presenter = null;
        protected global::System.Web.UI.WebControls.Repeater rptFollowerRequests;
        protected global::System.Web.UI.WebControls.ImageButton btnApproved;
        protected global::System.Web.UI.WebControls.ImageButton btnRejected;

        #region Public Properties
        public string Domain
        {
            get;
            set;
        }
        public string MyListName
        {
            get;
            set;
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                presenter = new FollowerRequestsPresenter(this);

                presenter.Load();
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }
        }

        public void BindFollowerRequests(List<FollowerRequest> requests)
        {
            try
            {
                rptFollowerRequests.DataSource = requests;
                rptFollowerRequests.DataBind();
            }
            catch
            {
                throw;
            }

        }

        //Falta definir...
        protected void btnApproveReject_OnClick(object sender, CommandEventArgs e)
        {
            try
            {
                //presenter.DeleteItem();
                switch (e.CommandName)
                {
                    case "Approve":
                        presenter.approveRequest(e.CommandArgument.ToString());
                        break;
                    case "Reject":
                        presenter.rejectRequest(e.CommandArgument.ToString());
                        break;
                }
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }
        }

        private void DisplayError(Exception ex)
        {
            this.Controls.Add(new LiteralControl("<div style='color:Red;display:none;'>" + ex.ToString() + "</div>"));
        }
    }
}